package com.bracketbird.client.gui.club.tournament;


import com.bracketbird.client.*;
import com.bracketbird.client.model.tournament.*;
import com.bracketbird.client.service.*;
import com.bracketbird.client.url.*;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.*;
import com.bracketbird.clientcore.appcontrol.*;
import com.bracketbird.clientcore.gui.*;
import com.bracketbird.clientcore.service.*;
import com.bracketbird.clientcore.style.*;
import com.bracketbird.clientcore.util.*;

import java.util.*;

/**
 *
 */
public class TournamentInfoPage extends SubPage<TournamentInfoPageController> {

    
    public TournamentInfoPage() {
        super();
    }


    public void doInit() {


        ButtonComponent controlPanel = new ButtonComponent("Create tournament");
            controlPanel.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    UserManager.validateIsMember();

                    CreateTournament cr = new CreateTournament();
                    cr.setClubId(UserManager.getInstance().getClub().getId());
                    cr.setNameOfTournament("New_Tournament_"+ DateFormats.dateFormat_tournament.format(new Date()));
                    cr.setTemplate(false);
                    BBService.createTournament(cr, new CallBack<CreateTournamentResult>() {
                        @Override
                        public void success(CreateTournamentResult result) {
                            UrlCommand urlC = UrlCommand.createEditTournament(UrlUtil.getBaseUrl(), new EditTournament(), result.getTournament().getClubId(), result.getTournament().getId());
                            Window.open(urlC.getUrl(), "_blank", null);
                        }

                        @Override
                        public void fail(Throwable t) {

                        }
                    });
                }
            });

        getContent().add(controlPanel, LayoutFac.button());






        getContent().add(new SimplePanelComponent(), new TextLayout("100%", null));
    }

    public String getHeader() {
        return "Info";
    }



    public void setFocus() {
    }



    protected void setSubPageHolder(Page subPage) {
        //ignore
    }
}